package com.ylyq.ylxx.controller;

import com.ylyq.ylxx.model.ResponseData;
import com.ylyq.ylxx.model.bean.OceanengineCreateGroupResult;
import com.ylyq.ylxx.model.bean.OceanengineGroupInfo;
import com.ylyq.ylxx.model.bean.OceanengineUpdateStatusGroupResult;
import com.ylyq.ylxx.model.request.*;
import com.ylyq.ylxx.service.IOceanegineGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName OceanengineGroupController
 * @Description TODO
 * @Author xiaweichao
 * @Date 2020/6/24 17:08
 * @Version 1.0
 */
@RestController
@RequestMapping("/oCeanengine/group")
@Api(description = "巨量引擎广告组的相关接口")
public class OceanengineGroupController {

    @Autowired
    private IOceanegineGroupService iOceanegineGroupService;

    @PostMapping("/getGroup")
    @ApiOperation(value = "获取广告组", response = OceanengineGroupInfo.class)
    public ResponseData getGroup(@Valid @RequestBody GetGroupRequest getGroupInfoRequest) {
        return new ResponseData(ResponseData.Result.SUCCESS, iOceanegineGroupService.getGroup(getGroupInfoRequest));
    }

    @PostMapping("/getGroupAndReport")
    @ApiOperation(value = "获取广告组和该广告组的数据",response = OceanengineGroupInfo.class)
    public ResponseData getGroupAndReport(@Valid @RequestBody GetGroupInfoRequest getGroupInfoRequest) {
        return iOceanegineGroupService.getGroupAndReport(getGroupInfoRequest);
    }

    //    @PostMapping("/createGroup")
//    @ApiOperation(value = "创建广告组")
//    public ResponseData createGroup(@Valid @RequestBody CreateGroupInfoRequest createGroupInfoRequest){
//        return iOceanegineGroupService.createGroup(createGroupInfoRequest);
//    }
    @PostMapping("/createBatchGroup")
    @ApiOperation(value = "批量创建广告组",response = OceanengineCreateGroupResult.class)
    public ResponseData createBatchGroup(@Valid @RequestBody List<CreateGroupInfoRequest> createGroupInfoRequest) {

        List<OceanengineCreateGroupResult> results = new ArrayList<>();
        for (CreateGroupInfoRequest temp : createGroupInfoRequest) {
            OceanengineCreateGroupResult groupResult = iOceanegineGroupService.createGroup(temp);
            results.add(groupResult);
        }
        return new ResponseData(ResponseData.Result.SUCCESS, results);
    }

    @PostMapping("/updateBatchGroup")
    @ApiOperation(value = "批量修改广告组",response = OceanengineCreateGroupResult.class)
    public ResponseData updateBatchGroup(@Valid @RequestBody List<UpdateGroupInfoRequest> updateGroupInfoRequest) {

        List<OceanengineCreateGroupResult> results = new ArrayList<>();
        for (UpdateGroupInfoRequest temp : updateGroupInfoRequest) {
            OceanengineCreateGroupResult groupResult = iOceanegineGroupService.updateGroup(temp);
            results.add(groupResult);
//            if(groupResult.getCode()!= AccountConstant.OCEANENGINE_SUCCESS_CODE){
//
//            }
        }
        return new ResponseData(ResponseData.Result.SUCCESS, results);
    }

    @PostMapping("/updateStatusBatchGroup")
    @ApiOperation(value = "批量更新广告组状态",response = OceanengineUpdateStatusGroupResult.class)
    public ResponseData updateStatusBatchGroup(@Valid @RequestBody UpdateStatusGroupInfoRequest updateGroupInfoRequest) {
        OceanengineUpdateStatusGroupResult groupResult = iOceanegineGroupService.updateStatusGroup(updateGroupInfoRequest);
        return new ResponseData(ResponseData.Result.SUCCESS, groupResult);
    }

}
